package pack423;

import java.io.*;

public class Th {
    public static void main(String[] args) {
        FileReader fr = null;
        StringBuffer buffer = new StringBuffer();
        try {
            fr = new FileReader("document/test.txt");
            char[] charBuffer = new char[1024];
            int count = fr.read(charBuffer);
            while (count > 0) {
                buffer.append(charBuffer, 0, count);
                count = fr.read(charBuffer);
            }
            System.out.println(buffer.toString());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fr != null) {
                try {
                    fr.close();
                    fr = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
            String str = "流泪是我老婆 我愿意爱他一生一世 么么哒";
            BufferedWriter bw = null;

            try {
                bw = new BufferedWriter(new FileWriter("document/test.txt"));
                bw.write(str);
                bw.newLine();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    bw.close();
                    bw = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }
    }
}